package com.jine.boot2.service.impl;

import com.jine.boot2.dao.UserRepository;
import com.jine.boot2.model.User;
import com.jine.boot2.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userPepository;

    @Override
    public List<User> listUser() {
        return this.userPepository.findAll();
    }

    @Override
    public User saveUser(User user) {
        return this.userPepository.save(user);
    }

    @Override
    public User findUser(String id) {
        return this.userPepository.getOne(id);
    }

    @Override
    public void deleteUser(String id) {
        this.userPepository.deleteById(id);
    }

    @Override
    public void updateUser(User user) {
        this.userPepository.saveAndFlush(user);
    }
}
